<?php
/**
 * Created by PhpStorm.
 * User: yancheng<cheng@love.xiaoyan.me>
 * Date: 2019/3/2
 * Time: 1:31 PM
 */
include 'inc/env.php';
if(!isset($_POST['login_user']) || empty($_POST['login_user'])){
    //location.href='login.php?error=1';
    die("<script>alert('用户名格式不正确');history.back()</script>");
}
if(!isset($_POST['login_pass']) || empty($_POST['login_pass'])){
    die("<script>alert('密码格式不正确');history.back()</script>");
}
//获取提交数据
$username = $_POST['login_user'];
$password = $_POST['login_pass'];
$all_user_data = get_all_users();
if(!isset($all_user_data[$username])){ //  判断是否存在用户
    die("<script>alert('登录用户不存在');history.back()</script>");
}
if($all_user_data[$username]['pass'] != md5($password)){
    die("<script>alert('登录密码不正确');history.back()</script>");
}

//保存用户数据到session
$_SESSION[USER_DATA_KEY] = $username;
header('Location: index.php?from=login');